
using Domain.Types;
using Infrastructure.AggregateBase;
using Infrastructure.Error;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;

[Table("SmsCode")]
public class SmsCodeAggregate : AggregateRoot<SmsCodeAggregate, int>
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public override int ID { get; set; }
    [StringLength(20)]
    public string Phone { get; set; }

    public SmsCodeType SmsCodeType { get; set; }
    [StringLength(10)]
    public string SmsCode { get; set; }
    public DateTime OutTime { get; set; }
    public bool IsUse { get; set; }
    public bool SendSuccess { get; set; }
    public string SendMsg { get; set; }

    /// <summary>
    /// 有效验证
    /// </summary>
    public void Valid()
    {
        if (OutTime < DateTime.Now)
        {
            throw new BizException("手机验证码已失效");
        }
        if (IsUse)
        {
            throw new BizException("手机验证码已失效");
        }
    }
}